(load "ex1-22.scm")

(define (next-test n)
    (if (= n 2)
        3
        (+ n 2)))

(define (prime? n)
    (define (smallest-divisor n)
        (define (find-divisor n test-divisor)
            (define (divides? a b)
                (= (remainder b a) 0))
            (cond   ((> (square test-divisor) n) n)
                    ((divides? test-divisor n) test-divisor)
                    (else (find-divisor n (next-test test-divisor)))))
        (find-divisor n 2))
    (= n (smallest-divisor n)))

(display "\n========================================\n")
(search-for-primes TEST-NUM)
(display "\n========================================\n")

; 速度确实更快，但也没有快一倍
; 比值接近 2
; 因为并非所有步骤都快了一倍，只是求 divisor 的时候快了约一倍，所以总的来说只是接近一倍